// RAPACH : RAPport d'ACtivité Hebdomadaire
// +----------------------------------------------------------------------+
// | RAPACH Version 1                                                     |
// +----------------------------------------------------------------------+
// | Copyright (c) 2013-2013 RAPACH                                       |
// +----------------------------------------------------------------------+
// | This file is part of RAPACH.                                         |
// |  RAPACH is free software: you can redistribute it and/or modify      |
// |  it under the terms of the GNU General Public License as published by|
// |  the Free Software Foundation, either version 3 of the License, or   |
// |  (at your option) any later version.                                 |
// |                                                                      |
// |  RAPACH is distributed in the hope that it will be useful,           |
// |  but WITHOUT ANY WARRANTY; without even the implied warranty of      |
// |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       |
// |  GNU General Public License for more details.                        |
// |                                                                      |
// |  You should have received a copy of the GNU General Public License   |
// |  along with RAPACH.  If not, see <http://www.gnu.org/licenses/>.     |
// |                                                                      |
// +----------------------------------------------------------------------+
// | FREDON CORSE                                                         |
// | Author: Olivier Poujade <olivier.poujade@fredon-corse.com>           |
// +----------------------------------------------------------------------+







function getXMLHttpRequest() {
	var xhr = null;

	
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
		return null;
	}
	
	return xhr;
}





function traitement_select_produit(idcat)
{


//alert(idprogramme);
	var xhr   = getXMLHttpRequest();


	xhr.open("POST", "ajax_zero/XMLHttpRequest_select_produit.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("idcat=" + idcat);


	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {

				//readData(xhr.responseXML);
				//alert("lu : " + xhr.responseText );



				var nodes   = xhr.responseXML.getElementsByTagName("item");
				var oSelect = document.getElementById("id_pdt");
				var oOption, oInner;
	
				oSelect.innerHTML = "";



				for (var i=0, c=nodes.length; i<c; i++)
				{
					oOption = document.createElement("option");
					oInner  = document.createTextNode(nodes[i].getAttribute("name"));
					oOption.value = nodes[i].getAttribute("id");	
					oOption.appendChild(oInner);
					oSelect.appendChild(oOption);

//il faudra faire une requÃªte sur la derniÃ¨re action faites avec ce user
//					if(nodes[i].getAttribute("id") == nodes[i].getAttribute("name"))
//					if(nodes[i].getAttribute("id") == '2')	
//					{oOption.selected = "selected";}

				}


			//et je vide le select de stock, puisqu'il va falloir choisir le produit
			//au cas ou un produit est été choisi au préalable

				var nodes   = xhr.responseXML.getElementsByTagName("item");
				var oSelect = document.getElementById("quantite");
				var oOption, oInner;
	
				oSelect.innerHTML = "";




			document.getElementById("loader").style.display = "none";
		}
		else if (xhr.readyState < 4)
		{
			document.getElementById("loader").style.display = "inline";
		}
	};

}










function traitement_select_pdt_stock(idproduit)
{


//alert(idprogramme);
	var xhr   = getXMLHttpRequest();


	xhr.open("POST", "ajax_zero/XMLHttpRequest_select_produit_stock.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("idproduit=" + idproduit);


	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {

				//readData(xhr.responseXML);
				//alert("lu : " + xhr.responseText );



				var nodes   = xhr.responseXML.getElementsByTagName("item");
				var oSelect = document.getElementById("quantite");
				var oOption, oInner;
	
				oSelect.innerHTML = "";

var stock_total = nodes[0].getAttribute("id");

				for (var i=1; i<=stock_total; i++)
				{
					oOption = document.createElement("option");
					oInner  = document.createTextNode(i);
					oOption.value = i;	
					oOption.appendChild(oInner);
					oSelect.appendChild(oOption);
				}





			document.getElementById("loader").style.display = "none";
		}
		else if (xhr.readyState < 4)
		{
			document.getElementById("loader").style.display = "inline";
		}
	};

}













function traitement_select_projet(idprogramme)
{


//alert(idprogramme);
	var xhr   = getXMLHttpRequest();


	xhr.open("POST", "ajax_zero/XMLHttpRequest_select_projet.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("idprogramme=" + idprogramme);


	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {

				//readData(xhr.responseXML);
				//alert("lu : " + xhr.responseText );



				var nodes   = xhr.responseXML.getElementsByTagName("item");
				var oSelect = document.getElementById("projet");
				var oOption, oInner;
	
				oSelect.innerHTML = "";



				for (var i=0, c=nodes.length; i<c; i++)
				{
					oOption = document.createElement("option");
					oInner  = document.createTextNode(nodes[i].getAttribute("name"));
					oOption.value = nodes[i].getAttribute("id");	
					oOption.appendChild(oInner);
					oSelect.appendChild(oOption);

//il faudra faire une requÃªte sur la derniÃ¨re action faites avec ce user
//					if(nodes[i].getAttribute("id") == nodes[i].getAttribute("name"))
//					if(nodes[i].getAttribute("id") == '2')	
//					{oOption.selected = "selected";}

				}





			document.getElementById("loader").style.display = "none";
		}
		else if (xhr.readyState < 4)
		{
			document.getElementById("loader").style.display = "inline";
		}
	};

}



function traitement_select_projet2(idprogramme)
{


//alert(idprogramme);
	var xhr   = getXMLHttpRequest();

//seulement l'appel Ã  la page qui est diffÃ©rent de traitement_select_projet !!, c'est pour ajouter le premier choix par dÃ©aut vide...
	xhr.open("POST", "ajax_zero/XMLHttpRequest_select_projet2.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("idprogramme=" + idprogramme);


	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {

				//readData(xhr.responseXML);
				//alert("lu : " + xhr.responseText );



				var nodes   = xhr.responseXML.getElementsByTagName("item");
				var oSelect = document.getElementById("projet");
				var oOption, oInner;
	
				oSelect.innerHTML = "";



				for (var i=0, c=nodes.length; i<c; i++)
				{
					oOption = document.createElement("option");
					oInner  = document.createTextNode(nodes[i].getAttribute("name"));
					oOption.value = nodes[i].getAttribute("id");	
					oOption.appendChild(oInner);
					oSelect.appendChild(oOption);

//il faudra faire une requÃªte sur la derniÃ¨re action faites avec ce user
//					if(nodes[i].getAttribute("id") == nodes[i].getAttribute("name"))
//					if(nodes[i].getAttribute("id") == '2')	
//					{oOption.selected = "selected";}

				}





			document.getElementById("loader").style.display = "none";
		}
		else if (xhr.readyState < 4)
		{
			document.getElementById("loader").style.display = "inline";
		}
	};

}



function traitement_select_projet3(idprogramme)
{


//alert(idprogramme);
	var xhr   = getXMLHttpRequest();

//seulement l'appel Ã  la page qui est diffÃ©rent de traitement_select_projet !!, c'est pour ajouter le premier choix par dÃ©aut vide...
	xhr.open("POST", "ajax_zero/XMLHttpRequest_select_projet2.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("idprogramme=" + idprogramme);


	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {

				//readData(xhr.responseXML);
				//alert("lu : " + xhr.responseText );



				var nodes   = xhr.responseXML.getElementsByTagName("item");
				var oSelect = document.getElementById("projet");
				var oOption, oInner;
	
				oSelect.innerHTML = "";



				for (var i=0, c=nodes.length; i<c; i++)
				{
					if(nodes[i].getAttribute("id") != '0') //elnlÃ¨ve le 'A sÃ©lectionner pour la suite' du XMLHttpRequest_select_projet2.php
					{
						oOption = document.createElement("option");
						oInner  = document.createTextNode(nodes[i].getAttribute("name"));
						oOption.value = nodes[i].getAttribute("id");	
						oOption.appendChild(oInner);
						oSelect.appendChild(oOption);
					}

//il faudra faire une requÃªte sur la derniÃ¨re action faites avec ce user
//					if(nodes[i].getAttribute("id") == nodes[i].getAttribute("name"))
//					if(nodes[i].getAttribute("id") == '2')	
//					{oOption.selected = "selected";}

				}





			document.getElementById("loader").style.display = "none";
		}
		else if (xhr.readyState < 4)
		{
			document.getElementById("loader").style.display = "inline";
		}
	};

}





function traitement_select_action(idprojet)
{


//alert(idprojet);
	var xhr   = getXMLHttpRequest();


	xhr.open("POST", "ajax_zero/XMLHttpRequest_select_action.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("idprojet=" + idprojet);


	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {

				//readData(xhr.responseXML);
				//alert("lu : " + xhr.responseText );



				var nodes   = xhr.responseXML.getElementsByTagName("item");
				var oSelect = document.getElementById("action");
				var oOption, oInner;
	
				oSelect.innerHTML = "";



				for (var i=0, c=nodes.length; i<c; i++)
				{
					oOption = document.createElement("option");
					oInner  = document.createTextNode(nodes[i].getAttribute("name"));
					oOption.value = nodes[i].getAttribute("id");	
					oOption.appendChild(oInner);
					oSelect.appendChild(oOption);

//il faudra faire une requÃªte sur la derniÃ¨re action faites avec ce user
//					if(nodes[i].getAttribute("id") == nodes[i].getAttribute("name"))
//					if(nodes[i].getAttribute("id") == '2')	
//					{oOption.selected = "selected";}

				}





			document.getElementById("loader").style.display = "none";
		}
		else if (xhr.readyState < 4)
		{
			document.getElementById("loader").style.display = "inline";
		}
	};

}


function traitement_select_action2(idprojet)
{


//alert(idprojet);
	var xhr   = getXMLHttpRequest();


	xhr.open("POST", "ajax_zero/XMLHttpRequest_select_action2.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("idprojet=" + idprojet);


	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {

				//readData(xhr.responseXML);
				//alert("lu : " + xhr.responseText );



				var nodes   = xhr.responseXML.getElementsByTagName("item");
				var oSelect = document.getElementById("action");
				var oOption, oInner;
	
				oSelect.innerHTML = "";



				for (var i=0, c=nodes.length; i<c; i++)
				{
					oOption = document.createElement("option");
					oInner  = document.createTextNode(nodes[i].getAttribute("name"));
					oOption.value = nodes[i].getAttribute("id");	
					oOption.appendChild(oInner);
					oSelect.appendChild(oOption);

//il faudra faire une requÃªte sur la derniÃ¨re action faites avec ce user
//					if(nodes[i].getAttribute("id") == nodes[i].getAttribute("name"))
//					if(nodes[i].getAttribute("id") == '2')	
//					{oOption.selected = "selected";}

				}





			document.getElementById("loader").style.display = "none";
		}
		else if (xhr.readyState < 4)
		{
			document.getElementById("loader").style.display = "inline";
		}
	};

}



function raz_select_action()
{
				var oSelect = document.getElementById("action");
				oSelect.innerHTML = "";
}